package com.example.je_0309;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/calc")
@RestController
public class CalcController {
    @RequestMapping("/sum")
    public String sum(Integer num1,Integer num2) {
        Integer sum = num1+num2;
        return "计算器计算结果:"+ sum;
    }

    @RequestMapping("/js")
    public String sum(Integer num1,Integer num2, String operator) {
        Integer result = 0;
        switch (operator) {
            case "+":
                result = num1 + num2;
                break;
            case "-":
                result = num1 - num2;
                break;
            case "*":
                result = num1 * num2;
                break;
            case "/":
                if (num2 == 0) {
                    return "除数不能为0";
                }
                result = num1 / num2;
                break;
        }
        return String.valueOf(
                result
        );
    }
}
